<%-- 
    Document   : ViewItemCategory
    Created on : Oct 2, 2011, 11:54:44 AM
    Author     : James
--%>

<%@page import="EntityState.ItemCategoryState"%>
<%@page import="EntityState.PartnerAccountState"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List, java.util.ArrayList"%>
<%@page import="java.util.ArrayList, BusinessLogic.Constants" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>FoodSage Partner Administration</title>
        <script language="javascript" type="text/javascript" src="../TransactWeb/js/jquery-1.6.4.min.js"></script>
        <script language="javascript" type="text/javascript" src="../TransactWeb/js/jquery.form.js"></script>
        <script type="text/javascript" src="../TransactWeb/js/fieldsetCollapse.js"></script>
        <script type="text/javascript" src="../TransactWeb/js/tcubmenu.js"></script>
        <script type="text/javascript" src="../TransactWeb/js/accordion.js"></script>
        <script type="text/javascript" src="../TransactWeb/js/scroller.js"></script>
        <script type="text/javascript" src="../TransactWeb/js/Utilities.js"></script>

        <link rel="stylesheet" type="text/css" href="../TransactWeb/css/gridsys.css" />
        <link rel="stylesheet" type="text/css" href="../TransactWeb/css/reset1.css" />
        <link rel="stylesheet" type="text/css" href="../TransactWeb/css/tcube.css" />
        <link href="../TransactWeb/css/gridsys.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" type="text/css" href="../TransactWeb/css/tcubaccd.css" />
        <script type="text/javascript">
	
            // Check Session to show relevant menus
            // Be sure to import Utilities.js in the script file	and declare partnerMenu as a servelet element
            window.onload = showPage('partnerMenu', 'leftnav');

            <%
    ArrayList data = (ArrayList) request.getAttribute("data");
    int result = ((Integer) data.get(0)).intValue();
    if (result == Constants.STATUS_SESSION_EXPIRED) {
            %>

                // If not logged in, use : 
                window.onload = showPage('topMenu', 'topmenu');
            <% } else {%>
                //IF logged in use : 
                window.onload = showPage('topMenulogout', 'topmenu');
            <% }%>

                //welcome msg
                window.onload = showPage('welcomeMenu','welcome');

                //footer
                window.onload = showPage('partnerFooter','footer');
            
                function update(num) 
                {
                    $.ajax({
                        type: "GET",
                        url:  "UpdateItemCategoryInfo",
                        data: {
                            id: $("#ID"+num).val(),
                            discount: $("#discount"+num).val(),
                            active: $("#active"+num).val()
                        },
                        success: function(response) {
                            var status = $(response).find("status").text();
                            $("#status").html(status);
                        },
                        dataType: "xml"
                    });
                }
                
                function deleteCategory(num) 
                {
                    if (confirm("All items in this category will also be deleted.\nDo you really want to delete it?")) {
                        $.ajax({
                            type: "GET",
                            url:  "DeleteStatus",
                            data: {
                                target: <%= Constants.DELETE_TARGET_ITEM_CATEGORY%>,
                                id: $("#ID"+num).val()
                            },
                            success: function(response) {
                                $("#row"+num).remove();
                                var status = $(response).find("status").text();
                                $("#status").html(status);
                            },
                            dataType: "xml"
                        });
                    }
                }
        </script>
    </head>
    <body>
        <div class="container_12">
            <!-- Header Nav -->
            <div class="grid_3"><img src="../TransactWeb/img/reservation/foodsglogo.png" width="146" height="178" /></div>
            <div class="grid_9 nav">
                <div id="topmenu"></div>
            </div>

            <div class="grid_12">
                <hr size="3" color="#CC6600" />
            </div>

            <%
                if (result == Constants.STATUS_SESSION_EXPIRED) {
            %>
            <!-- Content -->
            <div class="grid_12 content">
                <!-- Content Header -->

                SESSION EXPIRED

            </div>
            <%                } else if (result == Constants.STATUS_SUCCESSFUL) {
                List<ItemCategoryState> categories = (List<ItemCategoryState>) data.get(1);
            %>
            <!-- Welcome Message -->
            <div class="grid_12 welcome"><div id="welcome"></div></div>
            <!-- End Welcome Message-->

            <!-- End of Header Nav -->
            <!-- Menu / Planner -->
            <div class="grid_4">

                <div id="leftnav"></div>

            </div>
            <!--End Menu/ Planner -->
            <div class="grid_8 content">
                <table width="600" border="0">
                    <tr>
                        <td class="content_title">Item Category Management</td>
                    </tr>
                    <tr>
                        <td class="content_purpose">Item Category Info</td>
                    </tr>
                </table>
                <div id="status"></div>
                <table>
                    <tr>
                        <td>Number</td>
                        <td>ID</td>
                        <td>Name</td>
                        <td>Discount</td>
                        <td>Active</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <%
                        int i = 0;
                        for (ItemCategoryState ics : categories) {
                            i++;
                    %>
                    <tr id="<%= "row" + i%>">
                        <td><%= i%></td>
                        <td><input type="hidden" id="<%= "ID" + i%>" value="<%= ics.getId()%>" /></td>
                        <td><a href="ViewItemCategoryInfo?acion=<%= Constants.GET_ITEM_CATEGORY_INFO%>&id=<%= ics.getId()%>"><%= ics.getName()%></a></td>
                        <td><input type="text" id="<%= "discount" + i%>" value="<%= ics.getDiscount()%>" /></td>
                        <td><input type="checkbox" id="<%= "active" + i%>" value="1" checked="<%= ics.isActive()%>" /></td>
                        <td><button onclick="update(<%= i%>);">Update</button></td>
                        <td><button onclick="deleteCategory(<%= i%>);">Delete</button></td>
                    </tr>
                    <%
                        }
                    %>
                </table>

            </div> 
            <%
            }
            %>
            <!-- End Content -->
            <!-- Footer -->
            <div class="grid_12 footer">
                <div id="footer"></div>

            </div>
            <!-- End Footer-->
        </div>
    </body>
</html>
